import store from '@/store'

/**
 * @param {Array} value
 * @returns {Boolean}
 * @example see @/views/permission/directive.vue
 */
export default function checkPermission(value) {
  const roles = store.getters && store.getters.permissions
  if (value) {
    let hasPermission = false
    if (value.length > 0) {
      if (value instanceof Array) {
        for (const str of value) {
          if (roles.filter(r => r === str).length > 0) {
            hasPermission = true
            break
          }
        }
      } else {
        hasPermission = roles.some(role => {
          return value === role
        })
      }

      return hasPermission
    }
  } else {
    return false
  }
}
